From 11b038af5521de1da8e1d262c3fec0816921292b Mon Sep 17 00:00:00 2001 From: oliskoli Date: Thu, 7 Dec 2006 19:29:51 +0000 Subject: [PATCH] Add a function which extracts the filename portion from given full name. --- gpsbabel/defs.h | 2 ++ gpsbabel/util.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 8bb8f16cd..ab2024f95 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -726,6 +726,8 @@ char * convert_human_date_format(const char *human_datef); /* "MM,YYYY,DD" -> "% char * convert_human_time_format(const char *human_timef); /* "HH+mm+ss" -> "%H+%M+%S" */ char * pretty_deg_format(double lat, double lon, char fmt, int html); /* decimal -> dd.dddd or dd mm.mmm or dd mm ss */ +char * get_filename(const char *fname); /* extract the filename portion */ + /* * Character encoding transformations. */ diff --git a/gpsbabel/util.c b/gpsbabel/util.c index 1fabfe0c0..c0debfcc8 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -1627,3 +1627,17 @@ char *xml_attribute( xml_tag *tag, char *attrname ) } return result; } + +char *get_filename(const char *fname) +{ + char *res, *cb, *cs; + + cb = strrchr(fname, '\\'); + cs = strrchr(fname, '/'); + + if (cb == NULL) res = cs; + else if (cs == NULL) res = cb; + else res = (cs > cb) ? cs : cb; + + return (res == NULL) ? (char *) fname : ++res; +} -- 2.30.2